package com.bing.schoolmanager.Servlet;

import com.alibaba.fastjson2.JSON;
import com.bing.schoolmanager.pojo.ReturnData;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ckLogin")
public class CheckLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8");
         // 从session中获取当前用户登录信息
        Object admin = req.getSession().getAttribute("admin");
        if(admin!=null){
            resp.getWriter().write(JSON.toJSONString(new ReturnData(1,"在线",null)));
        }else {
            resp.getWriter().write(JSON.toJSONString(new ReturnData(0,"离线",null)));
        }
    }
}
